package br.com.bancodados.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;

public class FiltroActivity extends Activity {

	
	public static final String FILTER_TYPE = "filterType";
	public static final String FILTER_TEXT = "filterText";
	
	private EditText filterText;
	private RadioGroup filterGroup;
	private Button btnFiltrar;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.filtro_carros);
		
		filterText = (EditText) findViewById(R.id.filterText);
		filterGroup = (RadioGroup) findViewById(R.id.radioGroup);
		btnFiltrar = (Button) findViewById(R.id.btnFiltrar);
		
		btnFiltrar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				filter(filterText.getText().toString(), filterGroup.getCheckedRadioButtonId());
			}

			private void filter(String filterText, int checkedRadioButtonId) {
				Intent filterdList = new Intent(FiltroActivity.this, ListaCarrosActivity.class);
				filterdList.putExtra(FILTER_TEXT, filterText);
				filterdList.putExtra(FILTER_TYPE, checkedRadioButtonId);
				startActivity(filterdList);
			}
		});
	}
}
